/********************************
 *版权所有 CopyRight(c) 快程乐码信息有限公司所有，未经授权，不得复制、转发
 */
package com.jyx.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.jyx.excel.entity.CompleHeadData;
import com.jyx.excel.entity.DemoData;
import com.jyx.excel.entity.IndexData;
import com.jyx.excel.util.TestFileUtil;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/************
 *@Author yejx
 *@version v1.0
 *@create 2020/7/11 18:13
 *@Description TODO
 *
 */
@SpringBootTest
public class excludeOrIncludeWrite {

    /**
     * 指定写入的列
     * 创建excel对应的实体对象
     * 对entity实体 注解指定写入的列
     *
     */

    @Test
    public void indexWrite(){
        String fileName = TestFileUtil.getPath()+"excludeInclude"+System.currentTimeMillis()+".xlsx";
        EasyExcel.write(fileName, IndexData.class).sheet("sheetName").doWrite(data());
    }


    /**
     * 复杂头写入
     * 1. 创建excel对应的实体对象
     * 2. 使用 @ExcelProperty (value = {"合并字段名"，"字段名"} ,index = 0)注解指定复杂的头
     */

    @Test
    public void  complexHeadWrite(){
        String fileName = TestFileUtil.getPath()+"complexHeadWrite"+System.currentTimeMillis()+".xlsx";
        EasyExcel.write(fileName, CompleHeadData.class).sheet("sheetName").doWrite(data1());
    }







    /*模拟数据*/
    private List data() {
        ArrayList<IndexData> demoData = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            IndexData indexData = new IndexData();
            indexData.setName("叶");
            indexData.setStuId("173760"+i);
            indexData.setScore(i*10+"");
            demoData.add(indexData);
        }
        return demoData;
    }

    private List data1() {
        ArrayList<CompleHeadData> demoData = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            demoData.add(new CompleHeadData("张三丰","1737606"+i,i*10+"", new Date()));
        }
        return demoData;
    }





}
